<template>
	<view class="caseCollection">
		<view v-if="dataList">
			<view class="list" v-for="item in dataList" :key="item.id">
				<image class="img" :src=" item.url || '@/static/noPictures.jpg'" mode=""></image>
				<view class="content">
					<view class="c_title">{{ item.name }}</view>
					<view class="c_identify">
						<text v-for="el in item.labelList" :key="el.id">{{ el.name }}</text>
					</view>
					<text class="c_cont">{{ item.diseaseDesc }}</text>
				</view>
				<view class="btn">
					<van-button class="button" type="default" @click="fillIn(item)">填写</van-button>
				</view>
			</view>
		</view>
		<view v-else class="noData">
			<image src="@/static/noData.png"></image>
			<view class="text">暂无数据</view>
		</view>
		<view class="loading" v-show="isShowMore">没有更多数据了~</view>
		<van-toast id='van-toast' />
	</view>
</template>

<script>
	import {
		diseaseList
	} from '@/api/home'
	import { fileById } from '@/api/common'
	export default {
		name: 'caseCollection',
		data() {
			return {
				dataList: [{
					id: '1',
					title: '儿童湿疹案例征集',
					content: '儿童湿疹案例征集儿童湿疹案例征集'
				}],
				pagination: {
					pageSize: 10,
					pageNum: 1
				},
				total: '0',
				dataValue: {
					id: ''
				}
			}
		},
		onLoad(option) {
			this.dataValue.id = option.id
		},
		onShow() {
			this.getList();
		},
		onPullDownRefresh() {
			//下拉的生命周期
			this.pagination.pageNum = 1;
			setTimeout(() => {
				this.getList();
			}, 200)
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1300);
		},
		onReachBottom() {
			if ((this.pagination.pageSize * this.pagination.pageNum) >= this.total) {
				return
			}
			this.pagination.pageNum++;
			this.getList('more')
		},
		computed: {
			isShowMore() {
				if ((this.pagination.pageSize * this.pagination.pageNum) >= this.total) {
					return true
				} else {
					return false
				}
			}
		},
		methods: {
			//获取值
			getList(mode) {
				let params = {
					...this.pagination
				}
				if (this.dataValue.id) {
					params.id = this.dataValue.id
				}
				diseaseList(params).then(res => {
					if (mode == 'more') {
						this.dataList = this.dataList.concat(res.data.rows);
					} else {
						this.dataList = res.data.rows;
					}
					this.dataList.map((item,index) => {
						if (item.imgTheme) {
							fileById({ fileId: item.imgTheme }).then(res => {
								this.$set(item,'url', res.data.accessUrl);
							})
						}
					})
					this.total = res.data.total;
				})
			},
			fillIn(val) {
				uni.navigateTo({
					url: `./publishedCase?diseaseId=${val.id}&name=${val.name}&imgTheme=${val.imgTheme}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.caseCollection {
		width: 100%;
		box-sizing: border-box;
		padding: 0 20rpx;
		position: relative;

		.list {
			display: flex;
			margin-top: 20rpx;
			padding: 10rpx;
			border: 1rpx solid #8F8F94;

			.img {
				width: 200rpx;
				height: 200rpx;
			}

			.content {
				height: 100%;
				display: flex;
				width: calc(100% - 320rpx);
				margin-left: 20rpx;
				flex-direction: column;
				justify-content: center;
				padding: 20rpx 0;

				.c_title {

					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 36rpx;
				}

				.c_identify {
					margin: 20rpx 0;

					text {
						margin-left: 10rpx;
						background-color: #ccc;
						padding: 0 10rpx;
						font-size: 20rpx;
						margin: 10rpx 0 20rpx 10rpx;
					}
				}

				.c_cont {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 30rpx;
				}
			}

			.btn {
				width: 100rpx;
				position: relative;

				.button {
					width: 80rpx;
					height: 60rpx;
					position: absolute;
					bottom: 0;
					left: 0;
					font-size: 20rpx;

					/deep/ .van-button--normal {
						width: 100%;
						height: 100%;
						padding: 0 0;
					}
				}
			}
		}
	}
</style>
